package com.itheima.service;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.ReportDataService;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.OrderSettingDao;
import com.itheima.dao.SetmealDao;
import com.itheima.pojo.HotSetmealVCS;
import com.itheima.pojo.ReportDataVCS;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service(interfaceClass = ReportDataService.class)
@Transactional
public class ReportDataServiceImpl implements ReportDataService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Autowired
    private SetmealDao setmealDao;

    /*查询报告信息*/
    @Override
    public ReportDataVCS queryReportData() throws Exception {
        /*获取当前日期*/
        String date = DateUtils.parseDate2String(DateUtils.getToday());
        /*本周一的日期*/
        String thisWeekOne = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        /*本周日的日期*/
        String sundayWeekOne = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        /*本月一号*/
        String thisMonthOne = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        /*本月最后一天*/
        DateTime parse = DateUtil.endOfMonth(new Date());
        String endOfMonth = parse.toString("yyyy-MM-dd");


        ReportDataVCS report = new ReportDataVCS();

        //                  /*日期*/
        //                reportDate: null,
        report.setReportDate(date);

        //                /*今日新增会员数*/
        //                todayNewMember: 0,
        Integer todayNewMember = memberDao.queryTodayNewMember(date);
        report.setTodayNewMember(todayNewMember);
        //                /*总会员数*/
        //                totalMember: 0,
        Integer totalMember = memberDao.queryTotal();
        report.setTotalMember(totalMember);
        //                /*本周新增会员数*/
        //                thisWeekNewMember: 0,
        Integer thisWeekNewMember = memberDao.queryThisWeekNewMember(thisWeekOne);
        report.setThisWeekNewMember(thisWeekNewMember);
        //                /*本月新增会员数*/
        //                thisMonthNewMember: 0,
        Integer thisMonthNewMember = memberDao.queryThisWeekNewMember(thisMonthOne);
        report.setThisMonthNewMember(thisMonthNewMember);

        //                /*今日预约数*/
        //                todayOrderNumber: 0,
        Integer todayOrderNumber = orderDao.queryTodayOrder(date);
        report.setTodayOrderNumber(todayOrderNumber);

        //                /*今日到诊数*/
        //                todayVisitsNumber: 0,
        Integer todayVisitsNumber = orderDao.queryTodayVisits(date);
        report.setTodayVisitsNumber(todayVisitsNumber);

        //                /*TODO :本周预约数*/
        //                thisWeekOrderNumber: 0,
        Integer thisWeekOrderNumber = orderSettingDao.queryThisWeekOrderNumber(thisWeekOne,sundayWeekOne);
        report.setThisWeekOrderNumber(thisWeekOrderNumber);

        //                /*TODO :本周到诊数*/
        //                thisWeekVisitsNumber: 0,
        Integer thisWeekVisitsNumber = orderDao.queryThisWeekVisitsNumber(thisWeekOne,endOfMonth);
        report.setThisWeekVisitsNumber(thisWeekVisitsNumber);

        //                /*本月预约数*/
        //                thisMonthOrderNumber: 0,
        Integer thisMonthOrderNumber = orderSettingDao.queryThisWeekOrderNumber(thisMonthOne, sundayWeekOne);
        report.setThisMonthOrderNumber(thisMonthOrderNumber);

        //                /*本月到诊数*/
        //                thisMonthVisitsNumber: 0,
        Integer thisMonthVisitsNumber = orderDao.queryThisWeekVisitsNumber(thisMonthOne, endOfMonth);
        report.setThisMonthVisitsNumber(thisMonthVisitsNumber);

                          /*热卖套餐*/
        //                hotSetmeal: [
        //                    {name: '阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐', setmeal_count: 200, proportion: 0.222},
        //                    {name: '阳光爸妈升级肿瘤12项筛查体检套餐', setmeal_count: 200, proportion: 0.222}
        //                ]

        /*查询前四个热卖套餐*/
        List<HotSetmealVCS> hotSetmeal = setmealDao.queryHotSetmeal();

        report.setHotSetmeal(hotSetmeal);

        return report;
    }

    public static void main(String[] args) throws Exception {

        /*获取当前日期*/
        String date = DateUtils.parseDate2String(DateUtils.getToday());
        System.out.println("date = " + date);
        /*本周一的日期*/
        String thisWeekOne = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        System.out.println("thisWeekOne = " + thisWeekOne);

        /*本周日的日期*/
        String sundayWeekOne = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
        System.out.println("sundayWeekOne = " + sundayWeekOne);


        /*本月一号*/
        String thisMonthOne = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        System.out.println("thisMonthOne = " + thisMonthOne);


        DateTime parse = DateUtil.endOfMonth(new Date());
        String endOfMonth = parse.toString("yyyy-MM-dd");



    }
}
